package com.ctrip.cap.domain.benchmark;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class AppRunningInfo extends GeneralInfo {
	public int getTotalStartTimes() {
		return totalStartTimes;
	}
	public void setTotalStartTimes(int totalStartTimes) {
		this.totalStartTimes = totalStartTimes;
	}
	public int getTotalRunningTime() {
		return totalRunningTime;
	}
	public void setTotalRunningTime(int totalRunningTime) {
		this.totalRunningTime = totalRunningTime;
	}
	public String getPackageName() {
		return packageName;
	}
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}
	public HashMap<String,ActivityStartInfo> getActivitysStartInfo() {
		if(activitysStartInfo==null)
		{
			activitysStartInfo=new HashMap<String,ActivityStartInfo>();
		}
		return activitysStartInfo;
	}
	public void setActivitysStartInfo(HashMap<String,ActivityStartInfo> activitysStartInfo) {
		this.activitysStartInfo = activitysStartInfo;
	}
	private int totalStartTimes;
	private int totalRunningTime;
	private String packageName;
	private HashMap<String,ActivityStartInfo> activitysStartInfo;

	public AppRunningInfo diff(AppRunningInfo appRunningInfo)
	{
		if(!this.packageName.equals(appRunningInfo.getPackageName()))
		{
			return null;
		}
		AppRunningInfo info=new AppRunningInfo();

		info.setPackageName(packageName);
		info.setTotalRunningTime(totalRunningTime-appRunningInfo.getTotalRunningTime());
		info.setTotalStartTimes(totalStartTimes-appRunningInfo.getTotalStartTimes());
		
		HashMap<String,ActivityStartInfo> newStatus=new HashMap<String,ActivityStartInfo>();
		HashMap<String,ActivityStartInfo> oldStatus=appRunningInfo.getActivitysStartInfo();
		Iterator iter = this.activitysStartInfo.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			String key = (String) entry.getKey();
			ActivityStartInfo val = (ActivityStartInfo) entry.getValue();
			if(oldStatus.containsKey(key))
			{
				val=val.diff(oldStatus.get(key));
			}
			if(val.getStartTimes()!=0)
			{
				newStatus.put(key, val);
			}
		}
		info.setActivitysStartInfo(newStatus);
		return info;

	}



}
